home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14102 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  37 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: rand() source        
  5. Message-ID: <DpqLyq.8Kn@rci.ripco.com>
  6. X-Nntp-Sender: mambuhl@golden.ripco.com
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. Date: Fri, 12 Apr 1996 06:56:50 GMT
  10.  
  11. luchini@hybrid.ualr.edu (Dr. Chris Luchini)
  12. in <4kf88n$j5e@news.ualr.edu> asks:
  13.  
  14. >does anyone have the source for the ran() or rand() functions?
  15. >I could really use it ASAP!
  16.  
  17. They could be almost anything in your implementation, but as _examples_
  18. the standard gives (ISO 7.10.2.2)
  19.  
  20.         static unsigned long int next = 1;
  21.  
  22.         int rand(void)  /* RAND_MAX assumed to be 32767 */
  23.         {
  24.                 next = next * 1103515245 + 12345;
  25.                 return (unsigned int) (next/65536) % 32768;
  26.         }
  27.  
  28.         void srand(unsigned int seed)
  29.         {
  30.                 next = seed;
  31.         }
  32.  
  33.                                     
  34. --
  35. * Martin Ambuhl       net: mambuhl@ripco.com
  36. * Chicago, IL (USA)    
  37.